#include <stdio.h>

#include "sock.h"

#define SERVER_IP "127.0.0.1"
#define SERVER_PORT 6666

int main()
{
    int msgLen;
    message_t msg;
    int fd;
    char name[16];
    
    printf("Your name:");
    scanf("%s", name);
    system("clear");
    
    fd = connectServer(SERVER_IP, SERVER_PORT);

    user_t user = {0, "", fd};
    strcpy(user.name, name);

    write(fd, (void *)&user, sizeof(user_t));
    
    memset((void *)&msg, 0, sizeof(message_t));
    if ((msgLen = recv(fd, (void *)&msg, sizeof(message_t), 0)) == -1) {
        printf("Can't read from server.\n");
    }
    
    printf("%s\n", msg.info);
    
    //while (1) {
        
    //}
    memset((void *)&msg, 0, sizeof(message_t));
    scanf("%s", msg.info);
    strcpy(msg.from, user.name);
    strcpy(msg.to, "");

    write(fd, (void *)&msg, sizeof(message_t));
    recv(fd, (void *)&msg, sizeof(message_t), 0);

    printf("msg: %s", msg.info);

    close(fd);
    
    return 0;
}
